﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _26_SuperMaketProject
{
    //仓库
    class WareHouse
    {
        Dictionary<string, List<ProductFather>> dic = new Dictionary<string, List<ProductFather>>();
        //List<List<ProductFather>> list = new List<List<ProductFather>>();
        public WareHouse()
        {
            dic["SamSung"] = new List<ProductFather>();
            dic["Acer"] = new List<ProductFather>();
            dic["Banana"] = new List<ProductFather>();
            dic["JiangYou"] = new List<ProductFather>();
        }

        public void JinHuo(string type, int count)
        {
            if (!dic.ContainsKey(type))
            {
                //dic.Add(type, new List<ProductFather>());
                return;
            }

            Console.WriteLine("type:{0}, count:{1}", type, dic[type].Count);
           
            for (int i = 0; i < count; ++i)
            {
                switch (type)
                {
                    case "SamSung":
                        dic[type].Add(new SamSung(Guid.NewGuid().ToString(), 3000.88, "SamSung"));
                        break;
                    case "Acer":
                        dic[type].Add(new Acer(Guid.NewGuid().ToString(),2888.99,"Acer"));
                        break;
                    case "JiangYou":
                        dic[type].Add(new JiangYou(Guid.NewGuid().ToString(), 3.8, "JiangYou"));
                        break;
                    case "Banana":
                        dic[type].Add(new Banana(Guid.NewGuid().ToString(), 2.8, "Banana"));
                        break;
                }
            }
            
            Console.WriteLine("type:{0}, count:{1}", type, dic[type].Count);
        }

        public ProductFather[] QuHuo(string type, int count)
        {
            if (!dic.ContainsKey(type))
                return new ProductFather[0];

            int len = dic[type].Count < count ? dic[type].Count : count;
            ProductFather[] pro = new ProductFather[len];

            Console.WriteLine("type:{0}, count:{1}", type, dic[type].Count);
            pro = dic[type].Take(len).ToArray();
            dic[type].RemoveRange(0, len);
            Console.WriteLine("type:{0}, count:{1}", type, dic[type].Count);
            return pro;
         }
    }
}
